package servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.DeviceManager;

import entities.DeviceNC;
import fileServices.WebFileService;

/**
 * Servlet implementation class DeviceOverviewServlet
 */
@WebServlet("/DeviceOverview")
public class DeviceOverviewServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@EJB
	DeviceManager dm;

    public DeviceOverviewServlet() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		WebFileService wfs = new WebFileService();

		String hostIp = request.getParameter("hostIp");
		ArrayList<String> hostFiles = wfs.getFileNames(hostIp);
		request.setAttribute("hostFiles", hostFiles);
		
		String targetIp = request.getParameter("targetIp");
		ArrayList<String> targetFiles = wfs.getFileNames(targetIp);		
		request.setAttribute("targetFiles", targetFiles);
		
		DeviceNC host = dm.getDevice(request.getParameter("hostUUID"), false);
		request.setAttribute("host", host);
		
		DeviceNC target = dm.getDevice(request.getParameter("targetUUID"), false);
		request.setAttribute("target", target);
		
		request.getRequestDispatcher("WEB-INF/DeviceOverview.jsp").forward(request, response);
	}

}
